# -- coding: utf-8 -- 
# Name: 4_1_download_data.py

import argparse,httplib

REMOTE_SERER_HOST = 'www.python.org'
REMOTE_SERER_PATH = '/'

class HTTPClient:
    def __init__(self):
        self.host = host
    def fetch(self):
        http = httplib.HTTP(self.host)
        http.putrequest("GET", path)
        http.putheader("USER-AGENT", __file__)
        http.putheader("Host", self.host)
        http.putheader("Accept", "*/*")
        http.endheaders()
        try:
            errcode,errmsg,headers = http.getreply()
        except Exception, e:
            print errcode + errmsg + headers
        else:
            print self.host
        file = http.getfile()
        return file.read()

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='HTTP Client Example')
    parser.add_argument('--host', action="store", dest='host', default=REMOTE_SERER_HOST)
    parser.add_argument('--path', action="store", dest='path', default=REMOTE_SERER_PATH)
    given_args = parser.parse_args()
    host, path = given_args.host, given_args.path
    client = HTTPClient(host)
    print client.fetch(path)


